<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .tool-bar {
      position: fixed;
      top: 30%;
      right: 0;

      display: flex;
      flex-direction: column;
      align-items: center;

      width: 35px;
      background-color: pink;
    }

    .item {
      position: relative;
      width: 35px;
      height: 35px;
      margin-bottom: 1px;
      
      background-color: #7a6e6e;
      border-radius: 3px 0 0 3px;
    }

    .icon {
      display: inline-block;
      width: 100%;
      height: 100%;
      cursor: pointer;
      background-image: url(./img/toolbars.png);
    }

    .name {
      position: absolute;
      z-index: -1;
      right: 35px;
      top: 0;
      
      width:0;
      height: 35px;
      line-height: 35px;

      color: #fff;
      text-align: center;
      font-size: 12px;
      background-color: #7a6e6e;
      cursor: pointer;

      border-radius: 3px 0 0 3px;
      transition: width .2s ease;
    }

    .item:hover,
    .item:hover .name {
      background-color: #cd1926;
    }
    </style>
</head>
<body>
<div class="tool-bar">
    <div class="item">
        <i class="icon"></i>
        <div class="name">购物车</div>
    </div>
    <div class="item">
        <i class="icon"></i>
        <div class="name">收藏</div>
    </div>
    <div class="item">
        <i class="icon"></i>
        <div class="name">限时活动</div>
    </div>
    <div class="item">
        <i class="icon"></i>
        <div class="name">大礼包</div>
    </div>
</div>
<script>
    /* 通过精灵图显示图标 */
    const iconEls = document.querySelectorAll('.icon')
    for(let i=0;i<iconEls.length;i++){
        iconEls[i].style.backgroundPosition = `-48px ${-50*i}px`
    }
    /* 修改侧边栏的宽度大小 */
    const itemEls = document.querySelectorAll('.item')
    for(const item of itemEls){
        item.addEventListener('mouseenter',(event)=>{
            
            event.currentTarget.children[1].style.width='62px'
        })
        item.addEventListener('mouseleave',(event)=>{
            event.currentTarget.children[1].style.width=0
        })
    }
  
</script>
</body>
</html>